Infinite Loop when it's supposed to end because it has a clear condition that should be met